#ifndef __UTILS_HEAD
#define __UTILS_HEAD
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<fcntl.h>
#include<errno.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<sys/epoll.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<chrono>

struct user{
  char nickname[8];
  struct sockaddr_in addr;
  std::chrono::steady_clock::time_point lasttime;
};

struct result_code{
   int code;
   char msg[20];
};
struct message{
    char fname[8]; // 发送者id
    char tname[8];
   char m_msg[1024];

};
#ifdef __cplusplus
extern "C"{
#endif
void SETNOBLK(int socketfd);
int SOCK_CREATE(int type,int protocol);
int SOCK_BIND(int socketfd,const char* ipstr,int port);
int SOCK_REUSE(int socketfd);
int SOCK_CONN(int socketfd,const char* ipstr,int port);
int SOCK_LISTEN(int socketfd,int backlog);
int SOCK_ACCEPT(int socketfd,struct sockaddr* addr,socklen_t * len);
ssize_t Read(int fd,void * buf,ssize_t nbytes);
ssize_t Readn(int fd,void * buf,ssize_t nsum);
ssize_t Write(int fd,void *buf,ssize_t nbytes);
ssize_t Writen(int fd,void *buf,ssize_t nsum);
#ifdef __cplusplus
}
#endif
#endif